#include "GUIRoomba.h"
//Chandler Baker 
GUIRoomba:: GUIRoomba(int startX, int startY)
	: GUIBase()
{
	state= RoombaAtBase;
	loadImage("Resources/Sprites/Roomba.png"); 
	this->setOriginCenter();

	this->setX(startX);
	this->setY(startY);
	this->setZValue(ZVALUE_ROOMBA);
	this->setMovementSpeed(6);
	//this->setRotationSpeed(40);

}
//Roomba will pick up fallen parts when the button is clicked under non-norm 
void GUIRoomba:: doCleanUpNextPart()
{
	if(Part::fallenParts.size()>0)
	{ //rotate towards first part 
		if(x()==ROOMBA_BASEX && y()==ROOMBA_BASEY)
			this->rotateTowards(Part::fallenParts[0]->x(), Part::fallenParts[0]->y());	
		else //rotate slightly towards varying x locations 
			this->rotateTowards(Part::fallenParts[0]->x(), 0);
		moveTo(Part::fallenParts[0]->x(), Part::fallenParts[0]->y());
		state=RoombaMovingToPart;
	}
	
}
void GUIRoomba:: doneMoving()
{
	if(state==RoombaMovingToPart && Part::fallenParts.size()>0)
	{
		Part::fallenParts[0]->deleteLater(); 
		Part::fallenParts[0]->RemoveFromFloor();
		if(Part:: fallenParts.size()==0)
		{	//if there are no more parts, go back to base and change state
			this->rotateTowards(ROOMBA_BASEX, ROOMBA_BASEY);
			moveTo(ROOMBA_BASEX, ROOMBA_BASEY);
			state=RoombaMovingToBase;
		}
		else
			doCleanUpNextPart();
	}
	else if(state==RoombaMovingToBase)
	{
		state=RoombaAtBase;
		//this->rotateTowardsOverTime(ROOMBA_BASEX, ROOMBA_BASEY-20, this->boundingRect().x()/2,this->boundingRect().y()/2);
		this->rotateTowards(ROOMBA_BASEX, ROOMBA_BASEY -20);
	}
}